package cn.com.ieds.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author MACHENIKE
 */
public class CommonController {
    public void achieve(HttpServletRequest request, HttpServletResponse response, Object object) throws
            IllegalAccessException, InstantiationException, InvocationTargetException {
        String url = request.getRequestURI();
        String methodName = url.substring(url.lastIndexOf("/")+1);
        Class clazz = object.getClass();
        Method[] methods = clazz.getMethods();
        Object obj = clazz.newInstance();
        for(Method method : methods){
            if(methodName.equals(method.getName())){
                method.invoke(obj,request,response);
                System.out.println(method.getName());
                break;
            }
        }

    }
}
